# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-pytest-freezer
pkgver=0.4.8
pkgrel=1
pkgdesc='Pytest plugin providing a fixture interface for freezegun'
arch=('any')
url='https://github.com/pytest-dev/pytest-freezer'
license=('MIT')
depends=('python' 'python-pytest' 'python-freezegun')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-flit-core'
)
checkdepends=('python-pytest')
_commit='3be63e694fdc1714752e0fe8cb1b9cc0f639fdce'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  # install to temporary directory
  python -m installer --destdir="$(pwd)/tmp_install" dist/*.whl

  PYTHONPATH="$(pwd)/tmp_install$site_packages" \
    pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/pytest_freezer-$pkgver.dist-info/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
